package com.people.netmon.reddit.monitor.controller;


import ai.people.netmon.framework.domain.common.monitor.MonitorUsersListVO;
import ai.people.netmon.framework.domain.common.monitor.MonitorUsersVO;
import ai.people.netmon.framework.domain.reddit.monitor.entity.RedditUsers;
import ai.people.netmon.framework.domain.reddit.monitor.request.QueryRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import com.people.netmon.reddit.monitor.service.RedditUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
   监测 reddit用户信息接口
 *
 * @author zhenglin
 * @since 2022-03-14
 */
@RestController
@RequestMapping("/monitor/user/")
public class RedditUsersController {

    @Autowired
    RedditUsersService redditUsersService;

    /**
     * 分页查询
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link RedditUsers}>>
     */
    @PostMapping("/list")
    public Result<PageResponse<MonitorUsersListVO>> list(@RequestBody QueryRequest request){
        PageResponse<MonitorUsersListVO> response = redditUsersService.listPage(request);
        return ResultUtil.success(response);
    }

    /**
     * 通过username查询用户信息
     *
     * @param userName 用户名
     * @return {@link Result}<{@link MonitorUsersVO}>
     */
    @GetMapping("/{uname}")
    Result<MonitorUsersVO> getUsers(@PathVariable("uname") String userName){
        MonitorUsersVO redditUsers = redditUsersService.getUsers(userName);
        return ResultUtil.success(redditUsers);
    }
}
